/*
 * @Author: xiaosihan 
 * @Date: 2024-06-22 16:33:16 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2024-08-25 16:23:09
 */

// 零件详情页的公共状态

import { TreeDataNode } from "antd";
import { observable, configure } from "mobx";
configure({ enforceActions: "never" });
import { nanoid } from 'nanoid';
import partLableApi from "@api/partCollaborateApi";
import { get } from "lodash";
import { PartLableData } from "@type";

export type ModelLyaer = {
    name: string,
    children: Array<ModelLyaer>
}

const partCollaborateDemoStore = window.partCollaborateDemoStore = observable({

    // 模型id
    modelId: "",
    setModelId(modelId: string = "") {
        this.modelId = modelId;
    },

    //零件属于哪个用户的用户id
    userId: "",
    setUserId(userId: string) {
        this.userId = userId;
    },

    // 保存每个mesh 爆炸的方向
    blastDirection: [] as Array<{ x: number, y: number, z: number }>,
    setBlastDirection(blastDirection: Array<{ x: number, y: number, z: number }>) {
        this.blastDirection = blastDirection;
    },

    //爆炸的进度
    blastProgress: 0,
    setBlastProgress(blastProgress: number) {
        this.blastProgress = blastProgress;
    },

    //模型的尺寸
    modalSize: { x: 0, y: 0, z: 0 },
    setModalSize(modalSize: { x: number, y: number, z: number }) {
        this.modalSize = modalSize;
    },

    //加载中
    loadding: false,
    setLoadding(loadding: boolean) {
        this.loadding = loadding;
    },

    //模型的名称
    modelName: "",
    setModelName(modelName: string) {
        this.modelName = modelName;
    },

    //模型的大小
    size: "",
    setSize(size: string) {
        this.size = size;
    },

    //模型的日期
    createTime: "",
    setCreateTime(createTime: string) {
        this.createTime = createTime;
    },

    //模型结构
    modelLyaer: [] as Array<TreeDataNode & { isMesh: boolean }>,
    setModelLyaer(modelLyaer: Array<TreeDataNode & { isMesh: boolean }>) {
        this.modelLyaer = modelLyaer;
    },

    //当前选中的部位的id
    activeId: [] as Array<string>,
    setActiveId(activeId: Array<string> = []) {
        this.activeId = activeId;
    },

    //点选模型
    selectModel: false,
    setSelectModel(selectModel: boolean) {
        this.selectModel = selectModel;
        this.addMark = false;
    },

    //添加标记
    addMark: false,
    setAddMark(addMark: boolean) {
        this.addMark = addMark;
        this.selectModel = false;
    },

    // 控制器的类型
    controlType: "OrbitControls" as "MapControls" | "OrbitControls",
    setControlType(controlType: "MapControls" | "OrbitControls") {
        this.controlType = controlType;
    },

    //标签数据
    partLableDatas: [] as Array<PartLableData>,
    setPartLableData(partLableDatas: Array<PartLableData>) {
        this.partLableDatas = partLableDatas;
    },
    //添加评论
    addPartLableData(partLableData: PartLableData) {
        this.partLableDatas = [...this.partLableDatas, partLableData];
    },
    deletePartLableData(id: string) {
        this.partLableDatas = [...this.partLableDatas.filter(p => p.id !== id)];
    },
    //选中的评论
    selectLableId: "",
    setSelectLableId(selectLableId: string) {
        if (this.selectLableId === selectLableId) {
            this.selectLableId = "";
        } else {
            this.selectLableId = selectLableId;
        }
    },

    //隐藏标点
    hideLable: false,
    setHideLable(hideLable: boolean) {
        this.hideLable = hideLable;
    },

}, {}, { deep: false });

export default partCollaborateDemoStore;

